
* This file produces the analysis of progressive political ambition in Figure 7.

use "kolfu2012.dta", clear
drop if idnr ==.
joinby idnr using "list_plac_kolfu.dta"

* Age
ren Alder age
gen a1 = age<30
gen a2 = age>29 & age<40
gen a3 = age>39 & age<50
gen a4 = age>49 & age<65
gen a5 = age>64
tab age if a1==0 & a2 ==0 & a3==0 & a4 ==0 & a5==0

* Sex
gen woman = 1 if Kon==2
replace woman = 0 if Kon==1
	
* Student
gen stud = 1 if Q4==14
replace stud = 0 if stud==. & Q4!=.
	
* Global birth region
gen europe = 1 if Q6_1==5 | Q6_1==6
replace europe = 0 if europe==. & Q6_1>0 & Q6_1<8
count if europe ==1
gen outseurope=1 if Q6_1==7
replace outseurope=0 if outseurope==. & Q6_1<7

	
* Self-defined social class 
gen retired = 1 if age >65 & age!=.
replace retired = 0 if retired == . & age !=.
gen workerselfid = 1 if Q4==4 | Q4==5
replace workerselfid = 0 if workerselfid==. & Q4!=.
replace workerselfid = 0 if stud==1
replace workerselfid = . if retired==1
	
* Local party leader
gen listetta=1 if listplats==1
replace listetta=0 if listetta==.

* Councilors
tab Q11_2
gen kso = 1 if Q11_2 ==1
replace kso = 0 if kso==.
	
gen chair = 1 if Q13_1==1
replace chair = 1 if q13_10 ==1
		
foreach i of num 1/9 {
	replace chair = 1 if Q13_`i' ==1
	}
replace chair = 0 if chair ==. 

gen led=1
replace led = 0 if chair==1 
replace led = 0 if kso==1

* Keep parties with representation in parliamen
drop if Parti==10
drop if Parti==11
drop if Parti==9
drop if TYP==2 /* drop regional politicians */

****************************************************
* Figure 7. Analysis of progressive ambition	
****************************************************

* Municipality-party fixed effects
ren Kommunnr muni
egen muni_party = group(muni Parti)
ren Parti party

* Dependent variable
egen std_ambition = std(Q10)

* Sample of nonmissing data for count
gen sample =1 if workerselfid!=.
replace sample=. if muni_party==.
replace sample=. if a1==.
replace sample=. if a2==.
replace sample=. if a3==.
replace sample=. if a4==.
replace sample=. if a5==.
replace sample=. if woman==.
replace sample=. if europe==.
replace sample=. if stud==.

* Sample size count
count if sample==1 & listetta==1
count if sample==1 & led==1

* drop estimate-position

   foreach var in Q10 {
   	matrix C =J(18, 5,.)
	local i=0 
	local n=0
    
	foreach sample in sample {
	foreach pos in led chair {
	
	local i = `i'+1	 
	local n = `n'+1
	xi: areg `var' workerselfid if `sample'==1 & `pos'==1, abs(muni_party)
		
	matrix C[`i',1]=_b[workerselfid]
	matrix C[`i',2]=(_b[workerselfid]+1.96*_se[workerselfid])
	matrix C[`i',3]=(_b[workerselfid]-1.96*_se[workerselfid])
	matrix C[`i',4]=`n'-0.2
	matrix C[`i',5]=1
		
	xi: areg `var' workerselfid stud if `sample'==1 & `pos'==1, abs(muni_party)

	local i = `i'+1	 
	matrix C[`i',1]=_b[workerselfid]
	matrix C[`i',2]=(_b[workerselfid]+1.96*_se[workerselfid])
	matrix C[`i',3]=(_b[workerselfid]-1.96*_se[workerselfid])
	matrix C[`i',4]=`n'
	matrix C[`i',5]=2
	
	xi: areg `var' workerselfid stud a1-a5 woman if `sample'==1 & `pos'==1, abs(muni_party)

	local i = `i'+1	 
	matrix C[`i',1]=_b[workerselfid]
	matrix C[`i',2]=(_b[workerselfid]+1.96*_se[workerselfid])
	matrix C[`i',3]=(_b[workerselfid]-1.96*_se[workerselfid])
	matrix C[`i',4]=`n'+0.2
	matrix C[`i',5]=3
	}
	
	
	}
}	

matrix list C

svmat C
rename C1 estimate
rename C2 upper
rename C3 lower
rename C4 order
rename C5 position

twoway (rbar upper lower order if position==1, fcolor(black) lcolor(none) barwidth(.005)) ///
(scatter estimate order if position==1, mcolor(black) msize(large) msymbol(circle)) ///
(rbar upper lower order if position==3, fcolor(gs10) lcolor(gs10) barwidth(.005)) ///
(scatter estimate order if position==3, mcolor(gs10) msize(large) msymbol(circle))
 
